home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / zoo / zooext.c < prev    next >
C/C++ Source or Header  |  1980-01-02  |  20KB  |  661 lines

  1. #ifndef LINT
  2. /* derived from: zooext.c 2.21 88/08/24 02:39:04 */
  3. /*$Source: /usr/home/dhesi/zoo/RCS/zooext.c,v $*/
  4. /*$Id: zooext.c,v 1.9 91/07/09 01:54:13 dhesi Exp $*/
  5. static char sccsid[]="$Source: /usr/home/dhesi/zoo/RCS/zooext.c,v $\n\
  6. $Id: zooext.c,v 1.9 91/07/09 01:54:13 dhesi Exp $";
  7. #endif /* LINT */
  8.  
  9. /*
  10. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  11. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  12. (C) Copyright 1991 Rahul Dhesi -- All rights reserved
  13. */
  14. /* Extract file from archive.  Extracts files specified in parameter-list
  15.     from archive zoo_path.    If none specified, extracts all files from
  16.     archive. */
  17.  
  18. #include "options.h"
  19. #include "zoo.h"
  20. #include "parse.h"      /* defines struct for parse() */
  21.  
  22. #include "portable.h"   /* portable I/O definitions */
  23. #include "machine.h"    /* machine-specific declarations */
  24.  
  25. #include "zooio.h"
  26. #include "various.h"
  27.  
  28. #ifndef NOSIGNAL
  29. #include <signal.h>
  30. #endif
  31.  
  32. #include "zoofns.h"
  33.  
  34. #ifdef MODE_BIN        /* will need fileno() from stdio.h */
  35. # include <stdio.h>
  36. #endif
  37.  
  38. void makepath PARMS((char *));
  39. int needed PARMS((char *, struct direntry *, struct zoo_header *));
  40. void putstr PARMS((char *));
  41.  
  42. #ifdef FATTR
  43. int setfattr PARMS ((char *, unsigned long));
  44. #endif /* FATTR */
  45.  
  46. extern int quiet;
  47.  
  48. #include "errors.i"
  49.  
  50. /* Following two are used by ctrl_c() also, hence declared here */
  51. char extfname[LFNAMESIZE];                 /* filename of extracted file */
  52. char prtfname[LFNAMESIZE];                 /* name of extracted file on screen */
  53. static ZOOFILE this_file;                    /* file to extract */
  54.  
  55. static int tofile;                            /* true if not pipe or null device */
  56. extern unsigned int crccode;
  57. extern char *out_buf_adr;                    /* address of output buffer */
  58.  
  59. void zooext(zoo_path, option)
  60. char *zoo_path, *option;
  61. {
  62. char *whichname;                                    /* which name to extract */
  63. char matchname[PATHSIZE];                        /* for pattern matching only */
  64. #ifndef NOSIGNAL
  65. T_SIGNAL (*oldsignal) PARMS((int));       /* to save previous SIGINT handler */
  66. #endif
  67. ZOOFILE zoo_file;                                 /* open archive */
  68. long next_ptr;                                     /* pointer to within archive */
  69. struct zoo_header zoo_header;                 /* header for archive */
  70. int status;                                         /* error status */
  71. int exit_status = 0;                             /* exit status */
  72. int error_message;                                /* Whether to give error message */
  73. unsigned long disk_space;                        /* disk space left */
  74. int matched = 0;                                    /* Any files matched? */
  75. int overwrite = 0;                                /* force overwrite of files? */
  76. int supersede = 0;                                /* supersede newer files? */
  77. int needdel = 0;                                    /* extract deleted files too */
  78. int usepath = 2;                                    /* use path for extraction */
  79. int todot = 0;                                     /* extract relative to . */
  80. int badcrc_count = 0;                            /* how many files with bad CRC */
  81. int bad_header = 0;                                /* to avoid spurious messages later */
  82. long fiz_ofs = 0;                                 /* offset where to start */
  83. long dat_ofs = 0;                                 /* .. and offset of file data */
  84. int pipe = 0;                                        /* are we piping output? */
  85. int null_device = 0;                             /* are we sending to null device? */
  86. #ifdef FAST_EXT
  87. int fast_ext = 0;                                 /* fast extract as *.?Z? */
  88. #endif
  89. #ifndef PORTABLE
  90. int alloc_size;                                    /* disk allocation unit size */
  91. #endif
  92. struct direntry direntry;                        /* directory entry */
  93. int first_dir = 1;                                /* first dir entry seen? */
  94.  
  95. static char extract_ver[] = "Zoo %d.%d is needed to extract %s.\n";
  96. static char no_space[] = "Insufficient disk space to extract %s.\n";
  97.  
  98. while (*option) {
  99.     switch (*option) {
  100. #ifdef FAST_EXT
  101.         case 'z': fast_ext++; break;
  102. #endif
  103.         case 'x':
  104.         case 'e': break;
  105.         case 'N': null_device++; break;
  106.         case 'O': overwrite += 2; break;
  107.         case 'o': overwrite++; break;
  108.         case 'p': pipe++; break;
  109.         case 'S': supersede++; break;
  110.         case 'd': needdel++; break;
  111.         case 'q': quiet++; break;
  112.         case ':': usepath = 0; break;
  113.         case '/': usepath++; break;
  114.         case '.': todot++; break;
  115.         case '@':   /* if @m,n specified, fiz_ofs = m, dat_ofs = n */
  116.             {
  117.                 char *comma_pos;
  118.                 ++option;
  119.                 comma_pos = strchr(option, ',');
  120.                 if (comma_pos != NULL) {
  121.                     dat_ofs = calc_ofs (comma_pos + 1);
  122.                     *comma_pos = '\0';
  123.                 }
  124.                 fiz_ofs = calc_ofs(option);
  125.                 goto no_more;
  126.             }
  127.         default:
  128.             prterror ('f', inv_option, *option);
  129.             /* break; */
  130.     }
  131.     option++;
  132. }
  133.  
  134. no_more: /* come from exit in while loop above */
  135.  
  136.  
  137. if (overwrite == 1)                 /* must be at least 2 to begin with */
  138.     overwrite--;
  139.  
  140. if (null_device && pipe) {
  141.     prterror ('f', inv_option, 'p');
  142.     pipe = 0;
  143. }
  144.  
  145. if (overwrite && pipe)
  146.     prterror ('w', option_ignored, 'O');
  147.  
  148. #ifdef FAST_EXT
  149. if (null_device && fast_ext) {
  150.     prterror ('w', inv_option, 'N');
  151.     null_device = 0;
  152. }
  153. #endif
  154.  
  155. tofile = !pipe && !null_device;        /* sending to actual file */
  156.  
  157. zoo_file = zooopen(zoo_path, Z_READ);
  158.  
  159. if (zoo_file == NOFILE)
  160.     prterror ('f', could_not_open, zoo_path);
  161.  
  162. if (fiz_ofs != 0L) {                /* if offset specified, start there */
  163.     prterror ('m', start_ofs, fiz_ofs, dat_ofs);
  164.     zooseek (zoo_file, fiz_ofs, 0);
  165. } else {
  166.     /* read header */
  167.     frd_zooh (&zoo_header, zoo_file);
  168.     if ((zoo_header.zoo_start + zoo_header.zoo_minus) != 0L) {
  169.         prterror ('w', failed_consistency);
  170.         bad_header++;
  171.         exit_status = 1;
  172.     }
  173.     zooseek (zoo_file, zoo_header.zoo_start, 0); /* seek to where data begins */
  174. }
  175.  
  176. #ifndef PORTABLE
  177. disk_space = space (0, &alloc_size);         /* remember disk space left */
  178. #else
  179. disk_space = MAXLONG;                  /* infinite disk space */
  180. #endif
  181.  
  182. /* if piping output we open the output device just once */
  183. if (null_device) {
  184.     this_file = NULLFILE;
  185. } else if (pipe)
  186.     this_file = STDOUT;      /* standard output */
  187.  
  188. while (1) {
  189.     frd_dir (&direntry, zoo_file);
  190.     if (direntry.zoo_tag != ZOO_TAG) {
  191.         long currpos, zoolength;
  192.         prterror ('F', invalid_header);
  193.  
  194.         /* Note:  if header was bad, there's no point trying to find
  195.             how many more bytes aren't processed -- our seek position is
  196.             likely very wrong */
  197.  
  198.         if (!bad_header)
  199.             if ((currpos = zootell (zoo_file)) != -1L)
  200.                 if (zooseek (zoo_file, 0L, 2) != -1)
  201.                     if ((zoolength = zootell (zoo_file)) != -1L)
  202.                         printf (cant_process, zoolength - currpos);
  203.         zooexit (1);
  204.     }
  205.     if (direntry.next == 0L) {                /* END OF CHAIN */
  206.         break;                                            /* EXIT on end of chain */
  207.     }
  208.     /* when first direntry read, change dat_ofs from abs. pos. to rel. offset */
  209.     if (first_dir && dat_ofs != 0) {
  210.         dat_ofs -= direntry.offset;
  211.         first_dir = 0;
  212.     }
  213.     next_ptr = direntry.next + dat_ofs;         /* ptr to next dir entry */
  214.  
  215.     whichname = choosefname(&direntry);       /* which filename */
  216.     whichname = str_dup(whichname);           /* bug fix */
  217.     fixfname(whichname);                      /* fix syntax */
  218.     strcpy (matchname, fullpath (&direntry)); /* get full pathname */
  219.     if (zoo_header.vdata & VFL_ON)
  220.         add_version (matchname, &direntry);    /* add version suffix */
  221.  
  222. /* if extraction to subtree rooted at curr dir, modify pathname */
  223. #if 0
  224. #ifdef DIR_LBRACK
  225.     if (todot && direntry.dirname[0] == *DIR_LBRACK &&
  226.                      direntry.dirname[1] != *CUR_DIR)        {
  227.         char tmpstr[PATHSIZE];
  228.         strcpy (tmpstr, DIR_LBRACK);
  229.         strcat (tmpstr, CUR_DIR);
  230.         strcat (tmpstr, &direntry.dirname[1]);
  231.         strcpy (direntry.dirname, tmpstr);
  232.     }
  233. #endif
  234. #endif
  235.  
  236.     /* hard-coded '/' should be eventually removed */
  237.     if (todot && *direntry.dirname == '/') {
  238.         char tmpstr[PATHSIZE];
  239.         strcpy(tmpstr, direntry.dirname);
  240.         strcpy(direntry.dirname,CUR_DIR);
  241.         strcat(direntry.dirname, tmpstr);
  242.     }
  243.  
  244.     /* matchname now holds the full pathname for pattern matching */
  245.  
  246.     if ( ( (needdel && direntry.deleted) ||
  247.                 (needdel < 2 && !direntry.deleted)
  248.           ) && needed(matchname, &direntry, &zoo_header)) {
  249.         matched++;                /* update count of files extracted */
  250.  
  251.         if (direntry.major_ver > MAJOR_LZH_VER ||
  252.             (direntry.major_ver == MAJOR_LZH_VER &&
  253.                 direntry.minor_ver > MINOR_LZH_VER)) {
  254.                 prterror ('e', extract_ver, direntry.major_ver,
  255.                                     direntry.minor_ver, whichname);
  256.                 exit_status = 1;
  257.                 goto loop_again;
  258.         }
  259.  
  260.         /*
  261.         If extracting to null device, or if user requested extraction
  262.         of entire path, include any directory name in filename.
  263.         If extraction to current directory requested, and if extfname
  264.         begins with path separator, fix it */
  265.  
  266.         strcpy (extfname, whichname);
  267.         if ((usepath || null_device) && direntry.dirlen != 0) {
  268.             combine(extfname, direntry.dirname, whichname);
  269.             if (usepath > 1 && !null_device)
  270.                 makepath(direntry.dirname);         /* make dir prefix */
  271.         }
  272.  
  273.         strcpy(prtfname, extfname);
  274.         if (zoo_header.vdata & VFL_ON)
  275.             add_version (prtfname, &direntry);
  276.  
  277.         if (tofile) {
  278.             int present = 0;
  279.  
  280. #ifdef FAST_EXT
  281.             /*
  282.             if Z format (fast) extraction, extension is created as
  283.             follows:  for no current extension, new extension is "zzz";
  284.             for current extension "a", new extension is "azz";  for
  285.             current extension "ab", new extension is "azb";  and for
  286.             current extension "abc", new extension is "azc".
  287.             */
  288.  
  289.             if (fast_ext) {
  290.                 int length;
  291.                 struct path_st path_st;
  292.                 parse (&path_st, extfname);         /* split filename */
  293.                 strcpy (extfname, path_st.fname);   /* just root filename */
  294.                 length = strlen (path_st.ext);
  295.                 strcat (extfname, ".");
  296.                 if (length == 0)
  297.                     strcat (extfname, "zzz");        /* no ext -> .zzz */
  298.                 else if (length == 1) {
  299.                     strcat (extfname, path_st.ext);
  300.                     strcat (extfname, "zz");         /* *.?    -> *.?zz */
  301.                 } else { /* length is 2 or 3 */
  302.                     if (length == 2)                 /* allow .aa, .ab, etc. */
  303.                         path_st.ext[2] = path_st.ext[1];
  304.                     path_st.ext[1] = 'z';
  305.                     strcat (extfname, path_st.ext);  /* *.??   -> *.?z? */
  306.                 }
  307.                 strcpy(prtfname, direntry.fname);
  308.                 add_version (prtfname, &direntry);
  309.             }
  310. #endif    /* ifdef FAST_EXT */
  311.  
  312.             /* don't extract if archived file is older than disk copy */
  313.             if (!supersede && exists(extfname)) {
  314.                 unsigned int ddate, dtime;
  315. #ifdef GETUTIME
  316.                 getutime (extfname, &ddate, &dtime);
  317. #else
  318.                 ZOOFILE tfile;
  319.                 ddate = dtime = 0xffff;                 /* assume maximum */
  320.                 tfile = zooopen(extfname, Z_READ);
  321.                 if (tfile == NOFILE)
  322.                     goto loop_again;
  323.                 gettime (tfile, &ddate, &dtime);
  324.                 zooclose (tfile);
  325. #endif
  326.                 if (cmpnum (direntry.date, direntry.time, ddate, dtime) <= 0) {
  327.                     prterror ('m', "%-14s -- skipped\n", prtfname);
  328.                     goto loop_again;
  329.                 }
  330.             }
  331.  
  332.             if (overwrite) {
  333.                 this_file = zoocreate (extfname);
  334. #ifdef FATTR
  335.                 /* if can't open file, and OO option, make it writable first */
  336.                 if (this_file == NOFILE && overwrite >= 4 &&
  337.                         (direntry.fattr >> 22) == 1 && exists(extfname)) {
  338.                     setfattr (extfname, (unsigned long) (1L << 7) | direntry.fattr);
  339.                     this_file = zoocreate (extfname);
  340.                 }
  341. #endif /* FATTR */
  342.             } else {
  343.                 if (exists (extfname)) {
  344.                     present = 1;
  345.                     this_file = NOFILE;
  346.                 } else
  347.                     this_file = zoocreate (extfname);
  348.             }
  349.             error_message = 1;
  350.             if (this_file == NOFILE) {
  351.                 if (present == 1) {      /* if file exists already */
  352.                     char ans[20];              /* answer to "Overwrite?" */
  353.                     do {
  354. #ifdef EXT_ANYWAY
  355.                         printf ("%s exists; extract anyway? [Yes/No/All] ",
  356.                                     extfname);
  357. #else
  358.                         printf ("Overwrite %s (Yes/No/All)? ", extfname);
  359. #endif
  360.                         fflush (stdin);
  361.                         fgets (ans, sizeof(ans), stdin);
  362.                         str_lwr (ans);
  363.                     } while (*ans != 'y' && *ans != 'n' && *ans != 'a');
  364.  
  365.                     if (*ans == 'a')
  366.                         overwrite++;
  367.                     if (*ans == 'y' || *ans == 'a') {
  368.                         this_file = zoocreate(extfname);
  369.                         error_message = 1; /* give error message if open fails */
  370.                     } else {
  371.                         error_message = 0; /* user said 'n', so no error message */
  372.                     }
  373.                 } else {
  374.                     error_message = 1;    /* Real error -- give error message */
  375.                 }
  376.             } /* end if */
  377.         } /* end if */
  378.  
  379.         if (this_file == NOFILE) {         /* file couldn't be opened */
  380.             if (error_message == 1) {
  381.                 prterror ('e', "Can't open %s for output.\n", extfname);
  382.                 exit_status = 1;
  383.  
  384. #ifndef PORTABLE
  385.                 /* if error was due to full disk, abort */
  386.                 if (space(0, &alloc_size) < alloc_size)
  387.                     prterror ('f', disk_full);
  388. #endif
  389.  
  390.             }
  391.         } else if (zooseek (zoo_file, (direntry.offset + dat_ofs), 0) == -1L) {
  392.             prterror ('e', "Could not seek to file data.\n");
  393.             exit_status = 1;
  394.             close_file (this_file);
  395.         } else {
  396. #ifndef PORTABLE
  397.             /* check msdos's free disk space if we seem to be running low
  398.                 (within 1 cluster of being full) */
  399.             if (tofile && disk_space < direntry.org_size + alloc_size) {
  400.                 disk_space = space (0, &alloc_size);
  401.                 if (disk_space < alloc_size) {
  402.                     close_file (this_file);
  403.                     unlink (extfname);
  404.                     prterror ('f', disk_full);
  405.                 }
  406.             }
  407. #endif
  408.             if (tofile && disk_space < direntry.org_size) {
  409. #ifdef PORTABLE
  410.                 ;
  411. #else
  412.                 prterror ('e', no_space, prtfname);
  413.                 unlink (extfname);               /* delete any created file */
  414. #endif    /* portable */
  415.  
  416.             } else {
  417.  
  418. #ifdef FAST_EXT
  419.                 if (fast_ext) {            /* fast ext -> create header */
  420.                     void make_tnh PARMS((struct tiny_header *, struct direntry *));
  421.                     struct tiny_header tiny_header;
  422.                     make_tnh(&tiny_header, &direntry);
  423.                     zoowrite (this_file, (char *) &tiny_header, sizeof(tiny_header));
  424.  
  425.                     if (direntry.cmt_size != 0) { /* copy comment */
  426.                         long save_pos;
  427.                         save_pos = zootell (zoo_file);
  428.                         zooseek (zoo_file, direntry.comment, 0);
  429.                         getfile (zoo_file, this_file,
  430.                                   (long) direntry.cmt_size, 0);
  431.                         zooseek (zoo_file, save_pos, 0);
  432.                     }
  433.                 }
  434. #endif /* ifdef FAST_EXT */
  435.  
  436.                 crccode = 0;        /* Initialize CRC before extraction */
  437.                     if (!pipe) {
  438. #ifndef FAST_EXT
  439.                         prterror ('m', "%-14s -- ", prtfname);
  440. #else
  441.                         if (fast_ext)
  442.                             prterror ('m', "%-12s ==> %-12s -- ",
  443.                                 prtfname,  extfname);
  444.                         else
  445.                             prterror ('m', "%-12s -- ", prtfname);
  446. #endif /* FAST_EXT */
  447.  
  448.                     } else {               /* must be pipe */
  449.                         prterror ('M',"\n\n********\n%s\n********\n",prtfname);
  450.  
  451. #ifdef SETMODE
  452.                         MODE_BIN(this_file);           /* make std output binary so
  453.                                                                     ^Z won't cause error */
  454. #endif
  455.                     }
  456. #ifndef NOSIGNAL
  457.                 if (tofile)
  458.                     {
  459.                         oldsignal = signal (SIGINT, SIG_IGN);
  460.                         if (oldsignal != SIG_IGN)
  461.                             signal (SIGINT, ctrl_c); /* Trap ^C & erase partial file */
  462.                     }
  463. #endif /* not NOSIGNAL */
  464.  
  465.                 if (direntry.packing_method == 0)
  466.                     /* 4th param 1 means CRC update */
  467.                     status = getfile (zoo_file, this_file, direntry.size_now, 1);
  468.  
  469. #ifdef FAST_EXT
  470.                 else if (fast_ext)
  471.                     /* 4th param 0 means no CRC update */
  472.                     status = getfile (zoo_file, this_file, direntry.size_now, 0);
  473. #endif
  474.  
  475.                 else if (direntry.packing_method == 1) {
  476. #ifdef UNBUF_IO
  477. #include "ERROR"
  478.                     /* NOT PORTABLE -- DO NOT TRY THIS AT HOME */
  479.                     long lseek PARMS ((int, long, int));
  480.                     long tell PARMS ((int));
  481.                     int this_fd, zoo_fd;
  482.  
  483.                     /* get file descriptors */
  484.                     this_fd = null_device ? -2 : fileno (this_file);
  485.                     zoo_fd = fileno (zoo_file);
  486.  
  487.                     zooseek (zoo_file, zootell (zoo_file), 0);   /* synch */
  488.                     lseek (zoo_fd, zootell (zoo_file), 0);       /* ..again */
  489.                     if (!null_device) {
  490.                         zooseek (this_file, zootell (this_file), 0); /* synch */
  491.                         lseek (this_fd, zootell (this_file), 0);     /* ..again */
  492.                     }
  493.                     status = lzd(zoo_fd, this_fd);         /* uncompress */
  494.                     zooseek (zoo_file, tell (zoo_fd), 0);  /* resynch  */
  495.                     if (!null_device)
  496.                         zooseek (this_file, tell (this_fd), 0);/* resynch  */
  497. #else
  498.                     status = lzd (zoo_file, this_file);    /* uncompress */
  499. #endif
  500.                 } else if (direntry.packing_method == 2) {
  501.                     status = lzh_decode (zoo_file, this_file);
  502.                 } else {
  503.                     prterror ('e', "File %s:  impossible packing method.\n",
  504.                         whichname);
  505.                         unlink(extfname);
  506.                         goto loop_again;
  507.                 }
  508.  
  509.  
  510. #ifndef NOSIGNAL
  511.                 if (tofile)
  512.                     signal (SIGINT, oldsignal);
  513. #endif /* not NOSIGNAL */
  514.  
  515. #ifdef SETMODE
  516.                 if (pipe)
  517.                     MODE_TEXT(this_file);          /* restore text mode */
  518. #endif
  519.  
  520.                 if (tofile) {
  521.                     /* set date/time of file being extracted */
  522. #ifdef GETTZ
  523.                     void tzadj();
  524.                     /* adjust for original timezone */
  525.                     tzadj (&direntry);
  526. #endif
  527. #ifdef NIXTIME
  528.                     close_file (this_file);
  529.                     setutime (extfname, direntry.date, direntry.time);
  530. #else
  531.                     settime (this_file, direntry.date, direntry.time);
  532.                     close_file (this_file);
  533. #endif
  534. #ifdef FATTR
  535. /* Restore file attributes. Bit 23==1 means system-specific; we currently
  536. don't recognize this.  Bit 23==0 means use portable format, in which case
  537. bit 22==0 means ignore attributes.    Thus attributes are ignored if both
  538. bits 23 and 22 are zero, which is the effect of a zero-filled file
  539. attribute field.    Currently we restore file attributes if and only if
  540. bit 23==0 and bit 22==1. */
  541.  
  542.                     if ((direntry.fattr >> 22) == 1) {
  543.                         setfattr (extfname, direntry.fattr);
  544.                     }
  545. #endif /* FATTR */
  546.                 } /* end of if (tofile) ... */
  547.                 if (status != 0) {
  548.                     exit_status = 1;
  549.                     if (tofile)
  550.                         unlink (extfname);
  551.                     if (status == 2) {   /* was 1 (wrong) */
  552.                         memerr(0);
  553.                     /* To avoid spurious errors due to ^Z being sent to screen,
  554.                         we don't check for I/O error if output was piped */
  555.                     } else if (!pipe && (status == 2 || status == 3)) {
  556.                             prterror ('e', no_space, prtfname);
  557.                     }
  558.                 } else {
  559.                     /* file extracted, so update disk space.    */
  560.                     /* we subtract the original size of the file, rounded
  561.                         UP to the nearest multiple of the disk allocation
  562.                         size. */
  563. #ifndef PORTABLE
  564.                     {
  565.                         unsigned long temp;
  566.                         temp = (direntry.org_size + alloc_size) / alloc_size;
  567.                         disk_space -= temp * alloc_size;
  568.                     }
  569. #endif
  570.  
  571.                     if (
  572. #ifdef FAST_EXT
  573.                             !fast_ext &&
  574. #endif
  575.                             direntry.file_crc != crccode
  576.                         ) {
  577.                         badcrc_count++;
  578.                         exit_status = 1;
  579.                         if (!pipe) {
  580.                             if (!null_device)
  581.                                 prterror ('M', "extracted   ");
  582.                             prterror ('w', bad_crc, prtfname);
  583.                         }
  584.                         else {    /* duplicate to standard error */
  585.                             static char stars[] = "\n******\n";
  586.                             putstr (stars);
  587.                             prterror ('w', bad_crc, prtfname);
  588.                             putstr (stars);
  589.                             fprintf (stderr, "WARNING:  ");
  590.                             fprintf (stderr, bad_crc, prtfname);
  591.                         }
  592.                     } else
  593.                         if (!pipe)
  594.                             prterror ('M', null_device ? "OK\n" : "extracted\n");
  595.  
  596.                 } /* end if */
  597.             } /* end if */
  598.         } /* end if */
  599.     } /* end if */
  600.  
  601. loop_again:
  602.     zooseek (zoo_file, next_ptr, 0); /* ..seek to next dir entry */
  603. } /* end while */
  604.  
  605. close_file (zoo_file);
  606. if (!matched)
  607.     putstr (no_match);
  608.  
  609. if (badcrc_count) {
  610.     prterror ('w', "%d File(s) with bad CRC.\n", badcrc_count);
  611. } else if (null_device)
  612.     prterror ('m', "Archive seems OK.\n");
  613.  
  614. zooexit (exit_status);
  615.  
  616. } /* end zooext */
  617.  
  618. /* close_file() */
  619. /* closes a file if and only if we aren't sending output to
  620.     a pipe or to the null device */
  621.  
  622. void close_file (file)
  623. ZOOFILE file;
  624. {
  625.     if (tofile)
  626.         zooclose (file);
  627. }
  628.  
  629. /* Ctrl_c() is called if ^C is hit while a file is being extracted.
  630.     It closes the files, deletes it, and exits. */
  631. T_SIGNAL ctrl_c()
  632. {
  633. #ifndef NOSIGNAL
  634.     signal (SIGINT, SIG_IGN);     /* ignore any more */
  635. #endif
  636.     zooclose (this_file);
  637.     unlink (extfname);
  638.     zooexit (1);
  639. }
  640.  
  641. #ifdef FAST_EXT
  642. /* make_tnh copies creates a tiny_header */
  643. void make_tnh (tiny_header, direntry)
  644. struct tiny_header *tiny_header;
  645. struct direntry *direntry;
  646. {
  647.     tiny_header->tinytag = TINYTAG;
  648.     tiny_header->type = 1;
  649.     tiny_header->packing_method = direntry->packing_method;
  650.     tiny_header->date = direntry->date;
  651.     tiny_header->time = direntry->time;
  652.     tiny_header->file_crc = direntry->file_crc;
  653.     tiny_header->org_size = direntry->org_size;
  654.     tiny_header->size_now = direntry->size_now;
  655.     tiny_header->major_ver = direntry->major_ver;
  656.     tiny_header->minor_ver = direntry->minor_ver;
  657.     tiny_header->cmt_size = direntry->cmt_size;
  658.     strcpy (tiny_header->fname, direntry->fname);
  659. }
  660. #endif /* ifdef FAST_EXT */
  661.